package com.coder.bike.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.coder.bike.entity.Order;
import com.coder.bike.entity.RentalType;
import com.coder.bike.service.IOrderService;
import com.coder.bike.service.IRentalTypeService;
import com.coder.bike.utils.Result;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Slf4j
@RestController
@RequestMapping("/bike/order")
public class OrderController {

    @Resource
    private IOrderService orderService;
    @Resource
    private IRentalTypeService rentalTypeService;

    @PostMapping("/{start}/{size}")
    public Result search(@PathVariable int start, @PathVariable int size,
                         @RequestBody Order order) {
        Page<Order> page = new Page<>(start, size);
        return Result.success(orderService.search(page, order));
    }

    @PostMapping("/unfinished/{start}/{size}")
    public Result searchUnfinished(@PathVariable int start, @PathVariable int size,
                                   @RequestBody Order order) {
        Page<Order> page = new Page<>(start, size);
        return Result.success(orderService.searchUnfinished(page, order));
    }

    @PostMapping
    public Result save(@RequestBody Order order) {
        return orderService.save(order) ? Result.success() : Result.fail();
    }

    @PutMapping("/return")
    public Result returnBike(@RequestBody Order order) {
        return orderService.returnBike(order) ? Result.success() : Result.fail();
    }

    @GetMapping("/countViolation/{bikeNum}")
    public Result countViolation(@PathVariable String bikeNum) {
        return Result.success(orderService.countViolation(bikeNum));
    }

    @GetMapping("/doReturnDeposit/{orderId}")
    public Result doReturnDeposit(@PathVariable Integer orderId) {
        return orderService.returnDeposit(orderId) ? Result.success() : Result.fail();
    }


}